package estimation.impl;

import model.vo.Logging;
import utils.NoLimeUtils;
import estimation.EstimationAbstract;

public class MediaMovelJ3 extends EstimationAbstract {

	double time = 0;
	double distance = 0;	

	private double calculatePrediction() {
		distance = 0;
		time = 0;		
		Logging[] lm = logger.toArray(new Logging[super.logger.size()]);
		
		if (lm.length > getWindowSize()) {
			int initialSize=lm.length;
			for (int x = lm.length - 1; x > initialSize - getWindowSize(); x-=1) {
				time += (lm[x].getTime() - lm[x-1].getTime());
				distance += NoLimeUtils.subtract(lm[x].getPosition(), lm[x - 1]
						.getPosition());
			}
		}
		
		return distance / (time/1000);

	}

	public double getPrediction(double position) {
		// TODO Auto-generated method stub
		calculatePrediction();
		return position / calculatePrediction();
	}
	
	public int getWindowSize(){
		return 3;
	}
}
